/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.c1202m.dao;

import com.c1202m.hibernate.entities.QuyDinh;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 *
 * @author BACHLD
 */
public class QuyDinhDAO {

    public static QuyDinh docFile(String filename) {
        QuyDinh quyDinh = null;
        try {
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename));
//            int count = ois.readInt();
//            quyDinh = new QuyDinh[count];
//            for (int i = 0; i < count; i++) {
            quyDinh = (QuyDinh) ois.readObject();
//            }
            ois.close();
        } catch (IOException ex) {
            ex.printStackTrace();// Bắt lỗi của ois
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();// Bắt lỗi emps[i] = (Employee)ois.readObject();
        }
        return quyDinh;
    }

    public static void ghiFile(QuyDinh quyDinh, String filename) {
        try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(filename));
//            oos.writeInt(quyDinh.length);
//            for (QuyDinh qd : quyDinh) {
            oos.writeObject(quyDinh);
//            }
            oos.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
